within ThreeD_MBS_Dynamics.Examples.Rattleback;

model Case_of_Kane_Constraint
  extends Roll;
  // Ellipsoid semiaxes
  outer Real a1;
  outer Real b1;
  outer Real c1;
  outer Real delta;
  outer Real h;

    // Matrix of rotation with an angle delta about y-axis relative to principal-axis system
  parameter Real R[3, 3]=[cos(delta), 0, sin(delta); 0, 1, 0; -sin(delta), 0,
       cos(delta)];
  // Matrix of ellipsoid equation relative to canonic axes
  parameter Real B1[3, 3]=[1/a1^2, 0, 0; 0, 1/b1^2, 0; 0, 0, 1/c1^2];
  // Matrix of ellipsoid equation relative to principal axes
  parameter Real B[3, 3]=R*B1*transpose(R);
  // Normal vector to plane
  parameter Real n[3]={0,1,0};
  // Shift of a surface center
  parameter Real x0[3]={0,h,0};
  parameter Real d=0;
  Real lambda;
equation
  n*r = d;
  n = lambda*InPortB.T*B*(transpose(InPortB.T)*(r - InPortB.r) - x0);
end Case_of_Kane_Constraint;
